package com.example.reader.sdk.task;

import com.example.mtreader.MainActivity;
import com.example.reader.sdk.IReaderCallback;
import com.example.reader.sdk.RootCommand;
import com.example.reader.sdk.bean.ReaderBean;
import com.example.reader.sdk.utils.ThreadUtils;

public class ReaderTask extends ThreadUtils.Task<Void> {
    private IReaderCallback iReaderCallback;
    private ReaderBean readerBean;

    public ReaderTask(IReaderCallback iReaderCallback, ReaderBean readerBean) {
        this.iReaderCallback = iReaderCallback;
        this.readerBean = readerBean;
    }

    @Override
    public Void doInBackground() {
        if (iReaderCallback != null) {
            return null;
        }
        if (MainActivity.mt8deviceopen(0, 115200) > 0) {
            readerBean.setMessage("打开设备成功");
            iReaderCallback.onMsg(readerBean);

        } else {
            readerBean.setMessage("打开设备失败");
            iReaderCallback.onMsg(readerBean);
        }

        new RootCommand().executeCommands("chmod 777 /dev/bus/usb/001/*");
        return null;
    }

    @Override
    public void onSuccess(Void result) {

    }

    @Override
    public void onCancel() {

    }

    @Override
    public void onFail(Throwable t) {

    }


}
